package com.returnsoft.softphone.eao;

import java.io.Serializable;
import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import com.returnsoft.softphone.entity.Transfer;
import com.returnsoft.softphone.exception.CCenterExcepcion;
import com.returnsoft.softphone.exception.EaoExcepcion;

@LocalBean
@Stateless
public class TransferEao implements Serializable{
	
	private static final long serialVersionUID = 1L;

	@PersistenceContext(name = "CCenterEJB", unitName = "CCenterEJB")
	private EntityManager em;

	public List<Transfer> findTransfers(Integer campaignId)
			throws EaoExcepcion {
		try {
			TypedQuery<Transfer> q = em
					.createQuery(
							"SELECT t FROM Transfer t left join t.campaigns c WHERE c.id = :campaignId",
							Transfer.class);
			q.setParameter("campaignId", campaignId);
			return q.getResultList();
		} catch (Exception e) {
			e.printStackTrace();
			throw new EaoExcepcion(e.getMessage());
		}
	}

}
